package camo.utils
{
	import camo.controllers.helpers.TypeHelper;
	
	public class TypeHelperUtility
	{
		
		private static var __instance : TypeHelperUtility;
		private var _typeHelper:TypeHelper;
		
		/**
		 * Use TypeHelperUtility.instance to access method on the utility.
		 * @return instance: Reference to the class
		 */
		public static function get instance() : TypeHelperUtility {
			if(TypeHelperUtility.__instance == null) {
				TypeHelperUtility.__instance = new TypeHelperUtility(new SingletonEnforcer());
			}
			return TypeHelperUtility.__instance;
		}
		
		/**
		 * 
		 * @param enforcer
		 * 
		 */		
		public function TypeHelperUtility(enforcer : SingletonEnforcer) {
			if (enforcer == null) {
				throw new Error("Error: Cannot instantiate TypeHelperUtility directly, use TypeHelperUtility.instance instead of new.");
			}else {
				_typeHelper = new TypeHelper();
			}
		}
		
		public function getType(data : String, type : String, unknownTypeHandler:Function = null) : * {
			_typeHelper.getType(data,type, unknownTypeHandler);
		}
		
		/**
		 * <p>Converts a string to a boolean.</p>
		 */
		public function stringToBoolean(value : String) : Boolean {
			return _typeHelper.stringToBoolean(value);
		}
		
		/**
		 * <p>converts a hex color to a native number.</p>
		 */
		public function stringToUnitColor(value : String,hex : Boolean = false) : uint {
			return _typeHelper.stringToUnitColor(value,hex);
		}
		
		/**
		 * Use this to turn Yes No values into True or False.</p>
		 *	
		 *	@param value Accepts "yes" for true or "no" for false.
		 */
		public function convertYesNoToBoolean(value:String):Boolean{
			return TypeHelper.convertYesNoToBoolean(value);
		}
	}
}

internal class SingletonEnforcer {
}